<template>
	<view class="recordPrize">
		<view class="detailsBox">
			<view class="between oneList" v-for="(item,i) in list" :key="i">
				<view v-if="item.status>0" @click="onSkip(`/pages/draw/carry-prize-info?id=${item.id}&pageType=领取&jx=${item.jx}`)">
					<view>{{item.jxmc}}</view>
					<view class="time">{{item.createtime}}</view>
				</view>
				<view v-else>
					<view>{{item.jxmc}}</view>
					<view class="time">{{item.createtime}}</view>
				</view>
				<view @click="onSkip(`/pages/draw/carry-prize-info?id=${item.id}&pageType=领取&jx=${item.jx}`)" v-if="item.status>0&&item.jxtp==1" class="score1">{{item.jx_shipping_type == 1 ? "自提" : (item.jx_shipping_type == 2 ? "邮寄": (item.jx_shipping_type == 3 ? "回收" : ""))}}</view>
				<view class="score" v-if="item.status==0&&item.jxtp==1"
					@click="onSkip(`/pages/draw/carry-prize?id=${item.id}&pageType=领取&jx=${item.jx}`)">
					去领取
				</view>
				<view class="score" v-if="item.status==1&&item.jxtp==1" @click="onGetPrizeReceiving(item.id)">
					待收货</view>
				<view class="score" v-if="item.status==2&&item.jxtp==1"
					@click="onSkip(`/package/mine/prizeComment?id=${item.id}`)">
					追加评价</view>
				<view class="score" v-if="item.status==3&&item.jxtp==1">
					已评价</view>
			</view>
			<view class="flex-center addressImgBox" v-if="list.length==0">
				<image src="https://wx.2024csnl.com/static/noData.png"></image>
				暂无数据~
			</view>
			<view style="text-align: center;color: #999;" v-if="noMoreData&&list.length!=0">没有更多啦~</view>
		</view>
	</view>
</template>

<script>
	import {
		getPrizeRecord,
		getPrizeReceiving
	} from "../../api/index.js"
	export default {

		data() {
			return {
				noMoreData: false,
				list: [],
				pagenum: 1,
			}
		},
		onShow() {
			this.onreset()
		},
		onReachBottom() {
			this.pagenum += 1
			this.onGetPrizeRecord('bottom')
		},
		methods: {
			onreset() {
				this.pagenum = 1
				this.onGetPrizeRecord()
			},
			// 收货
			async onGetPrizeReceiving(id) {
				const result = await new Promise(resolve => {
					uni.showModal({
						title: '提示',
						content: '确认该奖品已经到货？',
						confirmColor: '#41644A',
						success(msg) {
							resolve(msg)
						}
					});
				})
				if (result.confirm) {
					const res = await getPrizeReceiving('s=/ApiChoujiang/receipt', {
						rid: id
					})
					const {
						msg,
						status
					} = res.data
					this.showToast(msg)
					if (status == 1) {
						setTimeout(() => {
							this.onreset()
						}, 2000)
					}
				}


			},
			async onGetPrizeRecord(type) {
				const res = await getPrizeRecord(`s=/ApiChoujiang/myprize&pagenum=${this.pagenum}`)
				const {
					status,
					msg,
					data
				} = res.data
				if (status == 1) {
					console.log(res)
					type == 'bottom' ? this.list.push(...data.datalist) : this.list = data.datalist
					this.pagenum != 1 && data.datalist.length == 0 ? this.noMoreData = true : this.noMoreData = false

				} else {
					this.showToast(msg)
				}
			},

		}
	}
</script>

<style lang="scss" scoped>
	.addressImgBox {
		flex-direction: column;
		color: #999;
		padding-top: 20%;

		image {
			width: 400rpx;
			height: 400rpx;
		}
	}

	.recordPrize {
		min-height: 100vh;
		background: rgb(247, 247, 247);
		margin-bottom: 100rpx;
	}

	.detailsBox {

		.oneList {
			margin-bottom: 2rpx;
			background: #fff;
			padding: 40rpx 30rpx;
			font-size: 28rpx;
		}

		.time {
			color: #666;
			font-size: 26rpx;
			margin-top: 20rpx;
		}
		
		.score1 {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-top: 20rpx;
			font-size: 30rpx;
			color: #ccc;
			font-size: 26rpx;
			width: 152rpx;
			height: 52rpx;
		}

		.score {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-top: 20rpx;
			font-size: 30rpx;
			background: #41644A;
			color: #fff;
			font-size: 26rpx;
			border-radius: 26rpx;
			width: 152rpx;
			height: 52rpx;
		}
	}
</style>